package com.sanshow.charging.receiver;

import static android.provider.ContactsContract.Intents.Insert.ACTION;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.Log;

import com.blankj.utilcode.util.ThreadUtils;
import com.sanshow.charging.MainActivity;

public class AutoStartBroadReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //开机启动
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
            Log.e("接收广播", "onReceive: 启动了。。。");

            /*Intent mainIntent = new Intent(context, MainActivity.class);
            mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(mainIntent);*/

            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            PackageManager packageManager = context.getPackageManager();
            Intent mainIntent = packageManager.getLaunchIntentForPackage("com.sanshow.charging");
            mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(mainIntent);
        }
    }
}
